require 'capybara/rspec'
require 'webmock/rspec'

WebMock.disable_net_connect!(allow_localhost: true)




# This file is copied to spec/ when you run 'rails generate rspec:install'

# 在命令行执行了` rails g rspec:install` 就会生成这个文件 -> spec_helper.rb

# set环境
ENV["RAILS_ENV"] ||= 'test'

#不管怎么样,跑测试还是需要初始化这个应用的
require File.expand_path("../../config/environment", __FILE__)

# 这个就是加载 rspec 自身相关的文件了!
require 'rspec/rails'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.


# rspec 对于 ruby 的一些文件支持自定义命名等.如, 在` spec/support/`及它的子文件夹里.
# 如果文件名以` spec/**/*_spec.rb`结尾的话,它会被自动当做是 spec 测试执行.如果不希望他被执行2次,就
# 不要在这个 spec 目录下使用这样的文件命名.
# 但是你可以在 rspec 的配置文件 ~/.rspec .rspec 或者. rspec-local 通过`-- pattern` 参数来指定

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  #config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  #config.use_transactional_fixtures = true

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = "random"

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explictly tag your specs with their type, e.g.:
  #
  #     describe UsersController, :type => :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://relishapp.com/rspec/rspec-rails/v/3-0/docs
  config.infer_spec_type_from_file_location!


  config.before(:each) do
    stub_request(:any, /api.github.com/).to_rack(FakeGitHub)
  end

  # config.before(:each) do
  #   stub_request(:get, /api.github.com/).
  #       with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
  #       to_return(status: 200, body: "stubbed response", headers: {})
  # end




end
